<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组元素是否相等验证</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f7fc;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 500px;
            padding: 20px;
            box-sizing: border-box;
        }

        h1 {
            text-align: center;
            color: #333;
            font-size: 24px;
        }

        .input-group {
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
        }

        .input-group input {
            padding: 10px;
            font-size: 16px;
            width: 100%;
            margin-right: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        .input-group button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .input-group button:hover {
            background-color: #45a049;
        }

        .result {
            text-align: center;
            font-size: 18px;
            padding: 10px;
            border-radius: 4px;
        }

        .result.success {
            background-color: #e8f5e9;
            color: #388e3c;
        }

        .result.fail {
            background-color: #ffebee;
            color: #d32f2f;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>检查数组元素是否相等</h1>
        <div class="input-group">
            <input type="text" id="inputArray" placeholder="请输入一组数字，用逗号分隔">
            <button onclick="checkEquality()">检查</button>
        </div>
        <div id="result" class="result"></div>
    </div>

    <script>
        // 判断数组中所有元素是否相等的函数
        const allEqual = arr => arr.every(item => item === arr[0]);

        // 检查输入是否相等的函数
        function checkEquality() {
            const input = document.getElementById('inputArray').value;
            const resultDiv = document.getElementById('result');

            // 将输入的字符串分割成数组
            const arr = input.split(',').map(item => item.trim());

            // 判断是否所有元素相等
            if (arr.length === 0 || arr.some(item => isNaN(item))) {
                resultDiv.textContent = "请输入有效的数字，且用逗号分隔！";
                resultDiv.className = "result fail";
            } else {
                const areEqual = allEqual(arr);
                if (areEqual) {
                    resultDiv.textContent = "所有元素相等！";
                    resultDiv.className = "result success";
                } else {
                    resultDiv.textContent = "元素不相等！";
                    resultDiv.className = "result fail";
                }
            }
        }
    </script>

</body>

</html>